package com.wk.job.heartbeat.slave;

import com.wk.job.Job;
import com.wk.job.heartbeat.JobStateHeartbeat;
import com.wk.job.heartbeat.JobStateHeartbeatTransferer;
import com.wk.net.heartbeat.source.HeartbeatSender;
import com.wk.net.heartbeat.source.HeartbeatSource;


public class JobStateHeartbeatSource {
	/**
	 * 发送心跳消息，汇报Job状态
	 * 
	 * @param observedJob
	 *            监视该Job的状态
	 * @param sender
	 *            传输心跳信号的底层实现
	 * @param period
	 *            发送周期（单位：秒）
	 */
	public JobStateHeartbeatSource(Job observedJob, HeartbeatSender sender, long period) {
		maker = new JobStateHeartbeatMaker(observedJob);
		impl = new HeartbeatSource<>(maker, new JobStateHeartbeatTransferer(), sender, period);
	}

	public void observe(Job job) {
		maker.observe(job);
	}

	public void start() {
		impl.start();
	}
	
	public void sendImmediately(){
		impl.sendImmediately();
	}

	private HeartbeatSource<JobStateHeartbeat> impl;

	private JobStateHeartbeatMaker maker;
}
